import axios, { get, post } from '@/api/axios'
import { type BiuJsonResult } from '@/api/biu-json-result'

export const urlPrefix: string = '/api/operator-package'

export const uploadOperatorPackageUrl: string = axios.defaults.baseURL + urlPrefix + '/upload'

export interface OperatorPackageInfo {
  id: string
  name: string
  tag: string
  md5: string
  operatorNumber: number
  createTime?: number
}

export interface UploadOperatorPackageResponse {
  message?: Map<string, string>
  info?: OperatorPackageInfo
}

export interface OperatorPackageInfoResponse {
  name: string
  className: string
  type: string
  description: string
  functionParameters: Array<any>
}

export function doQueryOperatorPackageList(keyword?: string) {
  const url = urlPrefix + '/query-list' + (keyword ? '?keyword=' + encodeURIComponent(keyword) : '')
  return get<BiuJsonResult<Array<OperatorPackageInfo>>>(url)
}

export function doQueryOperatorInfo(id: string) {
  return get<BiuJsonResult<Array<OperatorPackageInfoResponse>>>(urlPrefix + `/info?id=${id}`)
}

export function doDeleteOperatorPackage(ids: Array<string>) {
  return post(urlPrefix + '/delete', ids)
}
